package com.donquijote.proxy02.client;

import com.donquijote.proxy02.TimerInvocation;
import com.donquijote.proxy02.service;
import net.sf.cglib.proxy.Enhancer;

/**
 * @author 421527548@qq.com
 * @version V1.0
 * @title
 * @description
 * @date 2022-11-28 12:31
 */
public class Client {

    public static void main(String[] args) {

        //创建字节码增强器对象
        Enhancer enhancer = new Enhancer();

        //设置要继承的父类
        enhancer.setSuperclass(service.class);

        //设置回调增强函数
        enhancer.setCallback(new TimerInvocation());

        //设置代理对象，做两件事
        //  1、在内存中生成UserService类的子类，其实就是代理类的字节码
        //  2、创建代理对象
        service service = (service) enhancer.create();
        System.out.println(service.login("admin", "123")?"登录成功":"登录失败");

        System.out.println(service.logout());

        System.out.println(service.toString());


    }

}
